<?php 
/**
 * 分类管理控制器
 * 
 * @author 高强
 */
class Manager_GoodscatController extends Zend_Controller_Action
{
	protected $_output;
	private static $_model;
	
	public function init()
	{
		Zend_Loader::loadClass('CategoryModel');
		$this->_output = new Custom_Controller_Plugin_Output();
		$this->view->controller = $this->_request->getControllerName();
		
		self::$_model = new CategoryModel('st_goods_category', 'cat_left',  'cat_right', 'id');
	}
	
	public function listAction()
	{
		$action = $this->_request->getParam('a');
		
		switch($action)
		{
			case 'rows':
				$this->_helper->layout->disableLayout();
    			$this->_helper->viewRenderer->setNoRender(true);
    			
    			if($this->_request->isPost())
    			{
    				$post = $this->_request->getPost();
    				
    				$rows = self::$_model->getTreeList('cat_name');
    				$this->_output->grid($rows);
    			}
    			
				break;
		}
	}
	
	public function addAction()
	{
		$action = $this->_request->getParam('a');
		
		switch($action) 
		{
			case 'do':
				$this->_helper->layout->disableLayout();
				$this->_helper->viewRenderer->setNoRender(true);
				
				if($this->_request->isPost())
				{
					$post = $this->_request->getPost();
					$post['id'] = intval($post['parent_id']);
					unset($post['parent_id']);
					$this->_output->success(self::$_model->addTree($post), '添加分类错误！');
				}
				
				break;
				
			case 'combo':
				$this->_helper->layout->disableLayout();
    			$this->_helper->viewRenderer->setNoRender(true);
				$rows = self::$_model->getTreeList('cat_name');
				
				$this->_output->rows($rows);
				break;
		}
	}
	
	public function editAction()
	{
		
	}
}
?>